// +build ignore

package main

import (
	"fmt"
	"os"
	"time"

	"gopl/goroutine/thumbnail"
)

func makeThumbnails(filenames []string) error {
	errors := make(chan error)
	for _, f := range filenames {
		go func(f string) {
			_, err := thumbnail.ImageFile(f)
			errors <- err
		}(f)
	}

	for range filenames {
		if err := <-errors; err != nil {
			return err
		}
	}
	return nil
}

func main() {
	now := time.Now()
	err := makeThumbnails(os.Args[1:])
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("elapse:%.3f ms\n", 1000*time.Since(now).Seconds())
}
